package com.cloudconsumer.order.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import com.cloud.api.commons.pojo.CommonResult;
import com.cloud.api.commons.pojo.Payment;

import lombok.extern.slf4j.Slf4j;

@SuppressWarnings(value={"rawtypes", "unchecked"})
@RestController
@Slf4j
public class OrderController {
	
	// 调用支付订单服务端的ip+端口号
	// public static final  String PAYMENT_URL = "http://localhost:8001";
	public static final String PAYMENT_URL = "http://mcroservice-payment";

	@Autowired
	private RestTemplate restTemplate;

	/**
	 * 创建支付订单的接口
	 * @param payment
	 * @return
	 */
	@GetMapping("/consumer/payment/create")
	public CommonResult<Payment> create(Payment payment) {
		return restTemplate.postForObject(PAYMENT_URL + "/payment/create", payment, CommonResult.class);
	}

	/**
	 * 获取id获取支付订单
	 * @param id
	 * @return
	 */
	@GetMapping("/consumer/payment/get/{id}")
	public CommonResult<Payment> getPayment(@PathVariable("id") String id) {
		CommonResult commonResult = restTemplate.getForObject(PAYMENT_URL + "/payment/get/" + id, CommonResult.class);
		log.info("查询结果：{}", commonResult);
		return commonResult;
	}
}